//设置菜单栏中的模块分类 
function setHorizontalMenu(menuList){
// modify by cy
	var $menu=$(".homepage_menu");
	$(".item_menu").remove();//清空节点
	var $item_more=$(".item_more");
	var more_width=50;//更多选项的预设宽度
	var items_width=0;
	//装载 menu list
	for(var i = 0; i < menuList.length; i++){
        var icon=menuList[i]["img"]?menuList[i]["img"].split("?")[0]:"icon-001";
        var color=menuList[i]["img"]?(menuList[i]["img"].split("?")[1]?menuList[i]["img"].split("?")[1]:"#666"):"#666";
		var item="<div onclick='getSecMenu(" + menuList[i].menuId +")' class='item_menu "+icon+"' id="+menuList[i].menuId+" style='color:"+color+";'>" +
			// "<img  src='indexue/images/" + menuList[i].img +".png' alt='"+menuList[i].menuName+"'/>" +
			"<span>"+menuList[i].menuName+"</span></div>";
		$item_more.before(item);
		var list_width=$menu.width();//总宽度
		var item_width=getElWidth(menuList[i].menuId);//item宽度
		items_width=items_width+item_width;//items宽度
		if(items_width+more_width>list_width){//当加入元素宽度大于list的那么移除节点并加入更多菜单的选项卡
			$("#"+menuList[i].menuId).remove();
			$item_more.css("display","inline-block");
			break;
		}else {
			$item_more.css("display","none");
		}
	}
	
	if(menuList.length > 0){
		//初始化选中项
		var active_item=$(".homepage_menu").attr("data-active");
		active_item ?  $("#"+active_item).addClass("active") :$("#"+menuList[0].menuId).addClass("active");
	}
}
//获取元素 宽度(包括小数)
function  getElWidth(el){
	var elm=document.getElementById(el);
	var wd,rect=elm.getBoundingClientRect();
	if (rect.width) {
		wd = rect.width;
	} else {
		wd = rect.right - rect.left;
	}
	return  wd;
}

//设置用户姓名
function setLoginUserName(loginUserName){
	$(".loginUser_in").html(loginUserName);
}
var menuClickId = '';
//退出系统
function outSystem(){
	alert("learn system");
}
//展示更多功能分类
function setMoreMenu(menuList){
	//modify by cy
	$(".more_menu_con").remove();//清空
	var menu_con=$("<div class='more_menu_con'></div>");
	$(".item_more").append(menu_con);
	var morelist="<div class='more_menucon'>";
	for(var i = 0; i < menuList.length; i++){
		if($("#"+menuList[i].menuId).length<=0) {
            var icon=menuList[i]["img"]?menuList[i]["img"].split("?")[0]:"icon-001";
            var color=menuList[i]["img"]?(menuList[i]["img"].split("?")[1]?menuList[i]["img"].split("?")[1]:"#666"):"#666";
			morelist=morelist+"<div onclick='getSecMenu(" + menuList[i].menuId +")' class='item_menu "+icon+"' id="+menuList[i].menuId+" style='color:"+color+";'>" +
				// "<img  src='indexue/images/" + menuList[i].img +".png' alt='"+menuList[i].menuName+"'>" +
				"<span>"+menuList[i].menuName+"</span></div>";
		}
	}
	morelist=morelist+"</div>";
	//当鼠标移开后 删除更多框
	$("#topMenuStart").unbind("mouseleave click").bind("mouseleave click",function () {
		setTimeout(function () {
			$(".more_menu_con").fadeOut("normal",function(){
				$(this).remove();
			});
		},500);
		return false;
	});
	menu_con.html(morelist).focus();
	//初始化选中项
	var active_item=$(".homepage_menu").attr("data-active");
	active_item ?  $("#"+active_item).addClass("active") :$("#"+menuList[0].menuId).addClass("active");
	window.event? window.event.cancelBubble = true : e.stopPropagation();
}
var moreMenuPlanInfo = null;
//展示用户信息
function showUserInfo(name, identity, signstate){
	if($("#userInfoPlan").length == 1){
		$("#userInfoPlan").show();
		return;
	}
	var div;
	//外部边框
	div = "<div id='userInfoPlan''>";
	//div = div + "<img src='indexue/images/person_bg_top.png' style='float: left;'>";
	div = div + "<div class='userInfotopimg'></div>";
	div = div + "<div style='height: 120px;'>";   //yanglq
	div = div + "<div id='userInfo' class='userInfo'></div>";
	div = div + "</div>";
	div = div + "<div class='userInfoendimg'></div>";
	//div = div + "<img src='indexue/images/person_bg_bottom.png' style='float: left;'>";
	div = div + "</div>";
	$("#loginUser").append(div);

	//边框中内容
	div = "";
	/*	div = div + "<div>";
	 div = div + "<div   style='margin-left: 25px; margin-top: 18px; float:left;font-size:12px;'>换肤:</div>";
	 div = div + "<div   style='margin-left: 8px;margin-top: 18px; width:14px;height:14px;border-radius:2px;background-color:#424e5b;float:left;'></div>";
	 div = div + "<div   style='margin-left: 8px;margin-top: 18px; width:14px;height:14px;border-radius:2px;background-color:#3097de;float:left;'></div>";
	 div = div + "<div   style='margin-left: 8px;margin-top: 18px; width:14px;height:14px;border-radius:2px;background-color:#e86060;float:left;'></div>";
	 div = div + "</div>";*/
	div = div + "<div style='float: left; margin-top: 25px; margin-left: 25px;'>";
	div = div + "<div id='signin' class='text1' style='float: left; cursor: pointer;'  onclick='signRecordIn();'>";
	div = div + "<img src='indexue/images/person01_black.png' style='float: left; margin-left: 3px;'>";
	div = div + "<div style='margin-top: 22px; position: absolute;'>"+Base.I18n.getLangText('taface.page.index.ele.sign')+"</div>";//i18n:签到
	div = div + "</div>";
	div = div + "<div id='signout' class='text1' style='float: left; cursor: pointer;'  onclick='signRecordOut();'>";
	div = div + "<img src='indexue/images/person01_black.png' style='float: left; margin-left: 3px;'>";
	div = div + "<div style='margin-top: 22px; position: absolute;'>"+Base.I18n.getLangText('taface.page.index.ele.signout')+"</div>";//i18n:签退
	div = div + "</div>";

	//modify by xp 锁定功能未实现，隐藏，重新调整功能位置
	div = div + "<div id='modify' class='text1' style='float: left; cursor: pointer;margin-top:-1px;margin-left: 30px;'  onclick='openPwChangeWindow();'>";
	div = div + "<img src='indexue/images/person02_black.png' style='float: left; margin-left: 13px;'>";
	div = div + "<div style='margin-top: 22px; position: absolute;' >"+Base.I18n.getLangText('taface.page.general.ele.modifypassword')+"</div>";//i18n:修改密码
	div = div + "</div>";
	div = div + "</div>";
	div = div + "<div style='float: left; margin-top: 30px; margin-left: 25px'>";
	div = div + "<div id='positionswitch' class='text1' style='float: left; cursor: pointer;' onclick='showPositionSwitch();'>";
	div = div + "<img src='indexue/images/person05_black.png' style='float: left; margin-left: 3px;'>";
	div = div + "<div style='margin-top: 22px; position: absolute;margin-left: -10px;'>"+Base.I18n.getLangText('taface.page.index.ele.positionswitch')+"</div>";//i18n:岗位切换
    div = div + "</div>";

    div = div + "<div id='logout' class='text1' style='float: left; cursor: pointer;margin-top:-1px;margin-left: 30px;' onclick='logoutDwr();'>";
    div = div + "<img src='indexue/images/person03_black.png' style='float: left; margin-left: 13px;'>";
    div = div + "<div style='margin-top: 22px; position: absolute;margin-left: 10px;'>"+Base.I18n.getLangText('taface.page.index.ele.logout')+"</div>";//i18n:注销
    div = div + "</div>";

	div = div + "<div id='lock' class='text1' style='float: left; cursor: pointer; margin-left: 50px;' >";
	/*	div = div + "<img src='indexue/images/person04_black.png' style='float: left; margin-left: 3px;'>";
	 div = div + "<div style='margin-top: 22px; position: absolute;'>锁定</div>";*/
	div = div + "</div>";
	div = div + "</div>";

	/*	div = div + "<div id='lock' class='text1' style='float: left; cursor: pointer; margin-left: 50px;' >";
	 div = div + "<img src='indexue/images/person04_black.png' style='float: left; margin-left: 3px;'>";
	 div = div + "<div style='margin-top: 22px; position: absolute;'>锁定</div>";
	 div = div + "</div>";
	 div = div + "</div>";
	 div = div + "<div style='float: left; margin-top: 30px; margin-left: 13px'>";
	 div = div + "<div id='modify' class='text1' style='float: left; cursor: pointer;'  onclick='openPwChangeWindow();'>";
	 div = div + "<img src='indexue/images/person02_black.png' style='float: left; margin-left: 15px;'>";
	 div = div + "<div style='margin-top: 22px; position: absolute;' >修改密码</div>";
	 div = div + "</div>";
	 div = div + "<div id='logout' class='text1' style='float: left; cursor: pointer; margin-left: 50px;' onclick='logoutDwr();'>";
	 div = div + "<img src='indexue/images/person03_black.png' style='float: left; margin-left: 3px;'>";
	 div = div + "<div style='margin-top: 22px; position: absolute;'>注销</div>";
	 div = div + "</div></div>"; */

	$("#userInfo").append(div);

	if(signstate == "1") {
		$("#signout").show();
		$("#signin").hide();
	}else {
		$("#signin").show();
		$("#signout").hide();
	}

	$("#userInfoPlan").mouseleave(function(){
		eventUserInfo = setTimeout(function (){$("#userInfoPlan").hide();},500);
	}).mouseenter(function() {
		clearTimeout(eventUserInfo );
	});
}
var eventUserInfo = null;

$(window).resize(function(){
	setHorizontalMenu(menuList);
	//初始化选中项
	var active_item=$(".homepage_menu").attr("data-active");
	active_item ?  $("#"+active_item).addClass("active") :$("#"+menuList[0].menuId).addClass("active");
});